package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.pojo.Poet;
import com.coding.service.PoetService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/7/26
 **/
@Controller
@ResponseBody
@RequestMapping("poet")
public class PoetController {

    @Autowired
    PoetService poetService;

    @ApiOperation("分页查询诗人，可增加条件")
    @RequestMapping(value = "/getPageList", method = {RequestMethod.GET})
    public BaseModel getResList(@ApiParam("主要诗路id") @RequestParam(value = "poet_ways", required = false) Integer poet_ways,
                                @ApiParam("诗人朝代") @RequestParam(value = "poet_dynasty", required = false) String poet_dynasty,
                                @ApiParam("诗人tag") @RequestParam(value = "poet_tag", required = false) String poet_tag,
                                @ApiParam("诗人更多") @RequestParam(value = "poet_more1", required = false) String poet_more1,
                                @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        Poet poet = new Poet();
        if(poet_ways!=null){
            poet.setPoet_ways(poet_ways);
        }
        if (poet_dynasty!=null){
            poet.setPoet_dynasty(poet_dynasty);
        }
       if(poet_tag!=null){
           poet.setPoet_tag(poet_tag);
       }
       if(poet_more1!=null){
           poet.setPoet_more1(poet_more1);
       }

        poetService.getPoetlist(poet, pageQueryModel, model);
        return model;
    }

    @ApiOperation("根据诗人id查询诗人")
    @RequestMapping(value = "/getPoetById", method = {RequestMethod.GET})
    public BaseModel getpoetbyid(@ApiParam("poet_id") @RequestParam(value = "poet_id", required = true) int poet_id) throws Exception {
        BaseModel model = new BaseModel();
        poetService.getPoetbyid(poet_id, model);
        return model;
    }

    @ApiOperation("根据诗人name查询诗人")
    @RequestMapping(value = "/getPoetByName", method = {RequestMethod.GET})
    public BaseModel getpoetbyname(@ApiParam("poet_name") @RequestParam(value = "poet_name", required = true) String poet_name) throws Exception {
        BaseModel model = new BaseModel();
        poetService.getPoetbyname(poet_name, model);
        return model;
    }
}
